package com.huyiyu.dbproject.controller;

import com.huyiyu.dbproject.common.api.CommonResult;
import com.huyiyu.dbproject.dto.User;
import com.huyiyu.dbproject.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class LoginController {

  @Autowired
  private UserService userService;

  @GetMapping("/greeting")
  public void greeting(){
    System.out.println("greeting");
  }

  @PostMapping("/login")
  public CommonResult getUser(@RequestBody User user){
    String username = user.getUsername();
    String password = user.getPassword();
    System.out.println(username+", "+password);
    User temp = userService.getUser(user);
    if(temp==null){
      return CommonResult.failed();
    }
    return CommonResult.success();
  }
}
